<?php
/*-------------------------------------------------------------------------\
|
|  ========================================================
|  Fusion Registry GPL
|  Copyright (C) 2007 Fusion Scripts
|
|  This program is free software; you can redistribute it and/or
|  modify it under the terms of the GNU General Public License
|  as published by the Free Software Foundation; either version 2
|  of the License, or (at your option) any later version.
|
|  This program is distributed in the hope that it will be useful,
|  but WITHOUT ANY WARRANTY; without even the implied warranty of
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
|  GNU General Public License for more details.
|
|  You should have received a copy of the GNU General Public License
|  along with this program; if not, write to the Free Software
|  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
|  ========================================================
|
|  Email: info@fusionscripts.com
|  Web-Site: http://www.fusionscripts.com/
|
|  $Id: registry.php 4 2008-08-03 01:43:03Z registry.fusion $
|
\-------------------------------------------------------------------------*/

/**
 * Main module file for the Fusion Registry.
 *
 * This file is in charge of determining what code to run based on end-user
 * input. This is the only file which should be accessed directly, or the
 * only file which should be accessed directly through the parent integration
 * harness.
 *
 * @package Fusion Registry
 * @version $Id: registry.php 4 2008-08-03 01:43:03Z registry.fusion $
 */

/**
 * Configuration file for the registry
 */
require( ROOT_PATH.'sources/components_public/fusion_config.php' );

/**
 * Class component_public is the main program object.
 *
 * @package Fusion Registry
 */
class component_public
{
    var $ipsclass;

    /**
     * Constructor
     *
     * IPB will invoke this function, there are no passed
     * parameters and no return value. This function is the glue that
     * pieces all the run-time elements of the Fusion Registry together.
     * This function is the traffic cop of the Fusion Registry, it should
     * do very little procedural code, if any. The $commands array lists
     * all valid commands and actions, if the requested command is not
     * listed in this array it will not be run.
     */
    function run_component()
    {
        // Registered commands and actions
        $commands = array( 'view_attach'      => array( 'file' => 'attach'      , 'param' => 'view'              ),
                           'manage_gallery'   => array( 'file' => 'attach'      , 'param' => 'manage_menu'       ),
                           'do_new_attach'    => array( 'file' => 'attach'      , 'param' => 'do_new'            ),
                           'do_delete_attach' => array( 'file' => 'attach'      , 'param' => 'do_delete'         ),
                           'set_highlight'    => array( 'file' => 'attach'      , 'param' => 'set_highlight'     ),
                           'view_guestbook'   => array( 'file' => 'guestbook'   , 'param' => 'view'              ),
                           'add_comment'      => array( 'file' => 'guestbook'   , 'param' => 'do_add_comment'    ),
                           'delete_comment'   => array( 'file' => 'guestbook'   , 'param' => 'do_delete_comment' ),
                           'new_item'         => array( 'file' => 'item'        , 'param' => 'new_menu'          ),
                           'do_new_item'      => array( 'file' => 'item'        , 'param' => 'do_new'            ),
                           'manage_item'      => array( 'file' => 'item'        , 'param' => 'manage_menu'       ),
                           'modify_item'      => array( 'file' => 'item'        , 'param' => 'modify_menu'       ),
                           'do_modify_item'   => array( 'file' => 'item'        , 'param' => 'do_modify'         ),
                           'do_delete_item'   => array( 'file' => 'item'        , 'param' => 'do_delete'         ),
                           'view_item'        => array( 'file' => 'item'        , 'param' => 'view'              ),
                           'rate_item'        => array( 'file' => 'item'        , 'param' => 'rating_menu'       ),
                           'do_rate_item'     => array( 'file' => 'item'        , 'param' => 'do_rating'         ),
                           'idx'              => array( 'file' => 'main'        , 'param' => 'main_menu'         ),
                           'browse'           => array( 'file' => 'main'        , 'param' => 'browse'            ),
                           'search'           => array( 'file' => 'main'        , 'param' => 'search_menu'       ),
                           'do_search'        => array( 'file' => 'main'        , 'param' => 'do_search'         ),
                           'do_member_search' => array( 'file' => 'main'        , 'param' => 'do_member_search'  ),
                           'stats'            => array( 'file' => 'main'        , 'param' => 'stats'             ),
                           'new_mod'          => array( 'file' => 'modification', 'param' => 'new_menu'          ),
                           'do_new_mod'       => array( 'file' => 'modification', 'param' => 'do_new'            ),
                           'modify_mod'       => array( 'file' => 'modification', 'param' => 'modify_menu'       ),
                           'do_modify_mod'    => array( 'file' => 'modification', 'param' => 'do_modify'         ),
                           'do_delete_mod'    => array( 'file' => 'modification', 'param' => 'do_delete'         ),
                           'view_mod'         => array( 'file' => 'modification', 'param' => 'view'              ),
                         );

        // Only valid commands will get through
        if ( ( !empty($this->ipsclass->input['cmd']) ) and ( in_array($this->ipsclass->input['cmd'], array_keys($commands)) ) )
        {
            $exe = $this->ipsclass->input['cmd'];
        }
        else
        {
            // Default our command to idx
            $exe = 'idx';
        }

        // Get this show on the road!
        require( REGISTRY_PATH . "{$commands[$exe]['file']}.php" );

        $class_name = 'registry_'.$commands[$exe]['file'];

        $registry = new $class_name;
        $registry->ipsclass =& $this->ipsclass;
        $registry->auto_run( $commands[$exe]['param'] );
    }
}
?>